package cn.zhibang.yygh2.service.hosp.controller.api;

import cn.zhibang.yygh2.common.util.result.Result;
import cn.zhibang.yygh2.model.model.hosp.Hospital;
import cn.zhibang.yygh2.model.vo.hosp.DepartmentVo;
import cn.zhibang.yygh2.model.vo.hosp.HospitalQueryVo;
import cn.zhibang.yygh2.service.hosp.service.DepartmentService;
import cn.zhibang.yygh2.service.hosp.service.HospitalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(tags = "医院管理接口")
@RestController
@RequestMapping("/api/hosp/hospital")
public class HospitalApiController {

    @Autowired
    private HospitalService  hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @ApiOperation(value = "获取分页列表")
    @GetMapping("/{page}/{limit}")
    public Result index(@PathVariable Integer page, @PathVariable Integer limit , HospitalQueryVo hospitalQueryVo){
        //显示上线的医院
        //hospitalQueryVo.setStatus(1);
        Page<Hospital> hospitals = hospitalService.selectPage(page, limit, hospitalQueryVo);
        return Result.ok(hospitals);
    }

    @ApiOperation(value = "根据医院名称获取医院列表")
    @GetMapping("/findByHosname/{hosname}")
    public Result findByHosname(@ApiParam(name = "hosname",value = "医院名称",required = true) @PathVariable String hosname){
        return Result.ok(hospitalService.findByHosname(hosname));
    }



    @ApiOperation(value = "根据医院编号获取医院预约挂号详情")
    @GetMapping("findHospDetail/{hoscode}")
    public Result item(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode) {
        //返回医院预约挂号数据，使用Map集合接收
        Map<String, Object> map = hospitalService.item(hoscode);
        return Result.ok(map);
    }


    @ApiOperation(value = "根据医院编号获取科室列表")
    @GetMapping("/department/{hoscode}")
    public Result index(
            @ApiParam(name = "hoscode", value = "医院code", required = true)
            @PathVariable String hoscode) {
        //返回所有科室
        List<DepartmentVo> list = departmentService.findDeptTree(hoscode);
        return Result.ok(list);
    }







}
